#include "SectionMesh.h"

using SG::Algebra::Matrixd;
using SG::FEMSolver::Element::Meshes;

std::vector<SG::FEMSolver::BeamElement::BeamSecElementTypes> Meshes::GetAllElementTypes() const
{
    std::vector<SG::FEMSolver::BeamElement::BeamSecElementTypes> existingTypes;
    // 若Q9单元集合非空，加入Q9类型
    if (!q9Elements.empty())
    {
        existingTypes.push_back(SG::FEMSolver::BeamElement::BeamSecElementTypes::ElementType_Q9);
    }
    // 若T6单元集合非空，加入T6类型
    if (!t6Elements.empty())
    {
        existingTypes.push_back(SG::FEMSolver::BeamElement::BeamSecElementTypes::ElementType_T6);
    }
    
    // 后续新增单元集合（如Q8），需追加判断：
    
    return existingTypes;
}

Matrixd Meshes::ExtractElementNodeCoords (const std::vector<int>& nodeIds) const
{
    const int nodeSize = nodeIds.size();
    Matrixd coord(nodeSize,2);
    for (std::size_t iNode = 0; iNode < nodeSize; ++iNode)
    {
        const std::size_t nodeIdx = nodeIds[iNode] - 1;   // id-1 为索引
        coord(iNode, 0) = nodes[nodeIdx].y;
        coord(iNode, 1) = nodes[nodeIdx].z;
    }

    return coord;
}

void Meshes::TranslateNodes (const SG::DataStructure::Common::Real yS, const SG::DataStructure::Common::Real zS)
{
    for (std::size_t i = 0; i < nodes.size (); ++i)
    {
        nodes[i].y -= yS;
        nodes[i].z -= zS;
    }
}